<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>引入 Vue 的生命周期</title>
</head>
<body>
<div id="app">
    <h1 style="opacity: 0.8">Hello, World!</h1>
    <h1 v-bind:style="style">Hello, World!</h1>
</div>

<script type="module">
    import {createApp, ref, onMounted} from "../../../js/vue.esm-browser.js";

    let app = createApp(
        {
            setup() {

                let style = ref(
                    {
                        opacity: 0,
                    })

                onMounted(
                    () => {
                        let iter = 0

                        let interval = setInterval(
                            () => {
                                //   计算改变的次数，计算每次改变的值
                                // 通过 1000 次改变，每次 0.001
                                if (iter < 1000) {
                                    style.value.opacity += 0.001
                                    iter += 1
                                    console.log(style.value.opacity);
                                    // element.style.opacity = opacity
                                } else {
                                    clearInterval(interval)
                                }
                            },
                            10
                        );

                    }
                )
                return {
                    style
                }
            }
        }
    );

    app.mount("#app")
</script>
</body>
</html>